/**
 * @bsp_timer.c
 *
 * @copyright This file create by rensuiyi ,all right reserve!
 *
 * @author rensuiyi
 *
 * @date 20-9-30 下午7:01
 */
#include "bsp_timer.h"


int bsp_timer_reg_init(void) {


  NVIC_InitTypeDef NVIC_InitStructure1;
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //!< 30MHz


  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  NVIC_InitStructure1.NVIC_IRQChannel = TIM3_IRQn;
  NVIC_InitStructure1.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure1.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure1.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure1);

  TIM_DeInit(TIM3);
  TIM_TimeBaseStructure.TIM_Period = 999;
  TIM_TimeBaseStructure.TIM_Prescaler = 30000-1;//!< 1K
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  TIM_ClearFlag(TIM3, TIM_FLAG_Update);

  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

  TIM_Cmd(TIM3, ENABLE);

  return 0;
}


int bsp_timer_init(void) {
  bsp_timer_reg_init();
  return 0;
}

